part of menu;

//********************* group list menu ******************************/

List<Map<String, dynamic>> groupMenu = [
  {
    'label': '上移',
    'color': null,
    'icon': Icons.arrow_left,
    'onTap': forwardGroup,
  },
  {
    'label': '置顶',
    'color': Colors.blue,
    'icon': Icons.arrow_circle_up,
    'onTap': stickTop,
  },
  {
    'label': '下移',
    'color': null,
    'icon': Icons.arrow_right,
    'onTap': backwardGroup,
  },
  {
    'label': '分享',
    'color': Colors.orange,
    'icon': Icons.share,
    'onTap': outGroup,
  },
  {
    'label': '编辑',
    'color': Colors.green,
    'icon': Icons.edit,
    'onTap': editGroup,
  },
  {
    'label': '删除',
    'color': Colors.red,
    'icon': Icons.delete,
    'onTap': deleteGroup,
  },
];
// 前进
forwardGroup(BuildContext context, int gindex) {
  Navigator.of(context).pop();
  if (gindex - 1 < 0) {
    showInfoBlock("无法向前移");
  } else {
    context.read<GroupListModel>().moveGroup(gindex, gindex - 1);
    showInfoBlock("移动成功");
  }
}

//后退
backwardGroup(BuildContext context, int gindex) {
  Navigator.of(context).pop();
  if (gindex + 1 >= context.read<GroupListModel>().len) {
    showInfoBlock("无法向后移");
  } else {
    context.read<GroupListModel>().moveGroup(gindex, gindex + 1);
    showInfoBlock("移动成功");
  }
}

//增加用户
stickTop(BuildContext context, int gindex) {
  Navigator.of(context).pop();
  if (gindex == 0) {
    showInfoBlock("已经置顶");
  } else {
    context.read<GroupListModel>().moveGroup(gindex, 0);
    showInfoBlock("置顶成功");
  }
}

// 导出功能
outGroup(BuildContext context, int gindex) {
  showInfoBlock("暂时未开放");
  Navigator.of(context).pop();
}

// 编辑功能
editGroup(BuildContext context, int gindex) {
  Navigator.of(context).pop();
  Navigator.of(context).push(MaterialPageRoute(
    builder: (context) => AddGroupForm(gindex: gindex),
  ));
}

// 删除功能
deleteGroup(BuildContext context, int gindex) {
  Provider.of<GroupListModel>(context, listen: false).removeAt(gindex);
  showSuccBlock("删除成功");
  Navigator.of(context).pop();
}

//********************* 菜单路由 ******************************/

showGroupMenu(BuildContext context, int gindex) async {
  for (var grid in groupMenu) {
    grid['color'] = grid['color'] ?? modeColor(context);
  }

  List<Widget> menuList = List.generate(
    groupMenu.length,
    (i) => TIconText(
        text: groupMenu[i]['label'],
        icon: groupMenu[i]['icon'],
        color: groupMenu[i]['color'],
        onTap: () => groupMenu[i]['onTap'](context, gindex)),
  );
  await showModalBottomSheet(
    context: context,
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radius)),
    builder: (context) => Container(
      height: menuHeight,
      padding: const EdgeInsets.symmetric(vertical: verPadding * 2, horizontal: horPadding),
      child: Column(children: [
        const TitleText("菜单"),
        Column(children: [
          const Divider(height: 40),
          Wrap(
            spacing: (MediaQuery.of(context).size.width - 3 * boxSize) / 4,
            runSpacing: verMargin,
            children: menuList,
          )
        ]),
      ]),
    ),
  );
}
